﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

/// <summary>
/// RoleDao 的摘要说明
/// </summary>
public class RoleDao
{
	public RoleDao()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    //添加
    public static void add( string roleName,  string roleOrder)
    {
        if (roleOrder.Trim().Length <= 0) roleOrder = "0";
        OleDbConnection conn = DB.conn();
        if (conn != null)
        {
            conn.Open();
            OleDbCommand comm = new OleDbCommand();
            comm.Connection = conn;
            comm.CommandText = "insert into roles (roleName,roleOrder) values('" + roleName + "'," + roleOrder + ")";
            try { comm.ExecuteNonQuery(); }
            catch (Exception ex) { throw ex; }
            finally { comm.Dispose(); conn.Close(); }
        }
    }
    //更新
    public static void update(string id,string roleName, string roleOrder)
    {
        if (roleOrder.Trim().Length <= 0) roleOrder = "0";
        OleDbConnection conn = DB.conn();
        if (conn != null)
        {
            conn.Open();
            OleDbCommand comm = new OleDbCommand();
            comm.Connection = conn;
            comm.CommandText = "update roles set roleName='" + roleName + "',roleOrder=" + roleOrder + " where id=" + id;
            try { comm.ExecuteNonQuery(); }
            catch (Exception ex) { throw ex; }
            finally { comm.Dispose(); conn.Close(); }
        }
    }
    //删除(递归删除子栏目及此栏目)
    public static void del(string id)
    {
        OleDbConnection conn = DB.conn();
        if (conn != null)
        {
            conn.Open();
            OleDbCommand comm = new OleDbCommand();
            try
            {
                comm.Connection = conn;
                //删除此栏目
                comm.CommandText = "delete from roles where id in (" + id+")";
                comm.ExecuteNonQuery();
            }
            catch (Exception ex) { throw ex; }
            finally { comm.Dispose(); conn.Close(); }
        }
    }
}
